import 'package:flutter/material.dart';

/// 介绍页面（首页）
/// 展示项目介绍、功能特性等信息
class IntroPage extends StatelessWidget {
  const IntroPage({super.key});

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);
    final mutedColor = theme.colorScheme.onSurfaceVariant;
    
    return Scaffold(
      appBar: AppBar(
        title: const Text('首页'),
        elevation: 0,
      ),
      body: SingleChildScrollView(
        padding: const EdgeInsets.all(24),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            // 标题和图标
            Center(
              child: Column(
                children: [
                  Icon(
                    Icons.code_rounded,
                    size: 80,
                    color: theme.colorScheme.primary,
                  ),
                  const SizedBox(height: 16),
                  Text(
                    'GitCode 口袋工具',
                    style: theme.textTheme.headlineMedium?.copyWith(
                      fontWeight: FontWeight.bold,
                      color: theme.colorScheme.primary,
                    ),
                  ),
                  const SizedBox(height: 8),
                  Text(
                    '随身的 GitCode 搜索助手',
                    style: theme.textTheme.bodyLarge?.copyWith(
                      color: mutedColor,
                    ),
                  ),
                ],
              ),
            ),
            const SizedBox(height: 40),
            
            // 项目介绍
            _buildSection(
              context,
              title: '项目介绍',
              icon: Icons.info_outline,
              child: Text(
                'GitCode 口袋工具是一款基于 Flutter 开发的轻量级 GitCode 搜索工具，'
                '专为 OpenHarmony 平台优化。通过简洁的界面和强大的搜索功能，'
                '帮助开发者快速查找用户和仓库信息。',
                style: theme.textTheme.bodyMedium?.copyWith(height: 1.6),
              ),
            ),
            const SizedBox(height: 24),
            
            // 功能特性
            _buildSection(
              context,
              title: '功能特性',
              icon: Icons.star_outline,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  _buildFeatureItem(context, '🔍 用户搜索', '快速搜索 GitCode 用户，查看用户信息'),
                  const SizedBox(height: 12),
                  _buildFeatureItem(context, '📦 仓库搜索', '搜索代码仓库，查看仓库详情和统计信息'),
                  const SizedBox(height: 12),
                  _buildFeatureItem(context, '📱 分页加载', '支持下拉刷新和上拉加载更多，流畅浏览大量数据'),
                  const SizedBox(height: 12),
                  _buildFeatureItem(context, '🎨 Material Design 3', '现代化的 UI 设计，提供优秀的用户体验'),
                  const SizedBox(height: 12),
                  _buildFeatureItem(context, '🪟 多平台支持', '支持 OpenHarmony、Windows 等平台'),
                ],
              ),
            ),
            const SizedBox(height: 24),
            
            // 技术栈
            _buildSection(
              context,
              title: '技术栈',
              icon: Icons.build_outlined,
              child: Wrap(
                spacing: 8,
                runSpacing: 8,
                children: [
                  _buildTechChip(context, 'Flutter'),
                  _buildTechChip(context, 'Dio'),
                  _buildTechChip(context, 'pull_to_refresh'),
                  _buildTechChip(context, 'go_router'),
                  _buildTechChip(context, 'Material Design 3'),
                ],
              ),
            ),
            const SizedBox(height: 24),
            
            // 使用提示
            _buildSection(
              context,
              title: '使用提示',
              icon: Icons.lightbulb_outline,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  _buildTipItem(context, '1. 在"搜索"页面输入关键字和 Access Token'),
                  const SizedBox(height: 8),
                  _buildTipItem(context, '2. 选择搜索模式：用户或仓库'),
                  const SizedBox(height: 8),
                  _buildTipItem(context, '3. 点击"查询"按钮开始搜索'),
                  const SizedBox(height: 8),
                  _buildTipItem(context, '4. 点击"查看全部"可进入分页列表页面'),
                ],
              ),
            ),
            const SizedBox(height: 40),
            
            // 版本信息
            Center(
              child: Text(
                '版本 1.0.3',
                style: theme.textTheme.bodySmall?.copyWith(
                  color: mutedColor,
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildSection(
    BuildContext context, {
    required String title,
    required IconData icon,
    required Widget child,
  }) {
    final theme = Theme.of(context);
    
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          children: [
            Icon(icon, color: theme.colorScheme.primary, size: 24),
            const SizedBox(width: 8),
            Text(
              title,
              style: theme.textTheme.titleLarge?.copyWith(
                fontWeight: FontWeight.bold,
              ),
            ),
          ],
        ),
        const SizedBox(height: 16),
        child,
      ],
    );
  }

  Widget _buildFeatureItem(BuildContext context, String title, String description) {
    final theme = Theme.of(context);
    final muted = theme.colorScheme.onSurfaceVariant;

    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        const SizedBox(width: 8),
        Expanded(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                title,
                style: theme.textTheme.titleSmall?.copyWith(
                  fontWeight: FontWeight.w600,
                ),
              ),
              const SizedBox(height: 4),
              Text(
                description,
                style: theme.textTheme.bodyMedium?.copyWith(
                  color: muted,
                  fontSize: 14,
                ),
              ),
            ],
          ),
        ),
      ],
    );
  }

  Widget _buildTechChip(BuildContext context, String label) {
    return Chip(
      label: Text(label),
      padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
    );
  }

  Widget _buildTipItem(BuildContext context, String text) {
    final theme = Theme.of(context);
    final muted = theme.colorScheme.onSurfaceVariant;

    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        const SizedBox(width: 8),
        Expanded(
          child: Text(
            text,
            style: theme.textTheme.bodyMedium?.copyWith(
              color: muted,
              height: 1.5,
            ),
          ),
        ),
      ],
    );
  }
}

